<template>
	<div>
		<el-form :model="settingModel">
			<el-form-item label="appkey">
				<el-input v-model="settingModel.appkey"></el-input>
			</el-form-item>
			<el-form-item label="api">
				<el-input v-model="settingModel.url"></el-input>
			</el-form-item>
			<el-form-item label="官网地址">
				<el-input v-model="settingModel.officialAddress" readonly></el-input>
			</el-form-item>

		</el-form>
		<el-button type="primary" @click="saveSetting()">保存</el-button>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				settingModel: {
					appkey: '7d3b18e6794fbd96',
					url: 'https://api.jisuapi.com/isbn/query',
					officialAddress: 'https://www.jisuapi.com/'
				}
			}
		},
		created: function() {
			console.log()
			this.loadSetting()
			// this.$Settingstore.insert(this.settingModel, function(err, doc) {
			// 	console.log('inserted:', doc)
			// })
		},
		methods: {
			loadSetting() {
				var _self = this
				this.$Settingstore.findOne({}, function(err, docs) {
					console.log(docs)
					if (docs == null) {
						_self.$Settingstore.insert(_self.settingModel,function(err,doc){})
					}
					_self.settingModel = docs
				})
			},
			saveSetting() {
				var _self = this
				this.$Settingstore.update({
					_id: this.settingModel._id
				}, {
					$set: this.settingModel
				}, function(err, docs) {
					if(err){}
					else{
						_self.$message({
							type: 'success',
							message: '修改成功!'
						});
						_self.loadSetting()
					}
					
				})
			}
		}
	}
</script>

<style scoped>
	.title {
		color: #888;
		font-size: 18px;
		font-weight: initial;
		letter-spacing: .25px;
		margin-top: 10px;
	}

	.items {
		margin-top: 8px;
	}

	.item {
		display: flex;
		margin-bottom: 6px;
	}

	.item .name {
		color: #6a6a6a;
		margin-right: 6px;
	}

	.item .value {
		color: #35495e;
		font-weight: bold;
	}
</style>
